Are nested functions bad practice JavaScript